// 引入Vue
import Vue from 'vue';
// 引入vue路由
import VueRouter from 'vue-router';
// 使用路由
Vue.use(VueRouter)

// 引入各个路由组件
import Home from '../pages/home/Home.vue'
import Search from '../pages/search/Search.vue'
import Login from '../pages/login/Login.vue'
import Register from '../pages/register/Register.vue'
import Detail from  '../pages/detail/Detail.vue'
import AddCartSuccess from '../pages/addCartSuccess/AddCartSuccess.vue'
import ShopCart from '../pages/shopCart/ShopCart.vue'
// 创建路由并暴露
export default new VueRouter({
  mode: 'history',
  scrollBehavior(to, from, saveP) {
    //vue-router@3:属性x,水平轴位置 y,决定垂直位置
    //vue-router@4属性left,水平轴位置top,决定垂直位置
    return {
        y: 0,//如果当前数值为负数,不生效相当于零!!!!!
    }
},
  routes: [
    // 一级路由
    {
      name: 'home',
      path: '/home',
      component: Home,
      meta: {
        isShow: true,
      }
    },
    {
      name:'search',
      path: '/search',
      component: Search,
      meta: {
        isShow: true,
      }
    },
    {
      path: '/login',
      component: Login,
      meta: {
        isShow: false,
      }
    },
    {
      path: '/register',
      component: Register,
      meta: {
        isShow: false,
      }
    },
    {   //数据详情路由组件
      name:'detail',
      path:'/detail/:skuId',
      component:Detail,
      meta:{
        isShow: true,
      }
    },
    {
      // 添加到购物车
      name:'addCartSuccess',
      path: '/addCartSuccess/:skuId/:skuNum',
      component: AddCartSuccess,
      meta: {
        isShow: true,
      }
    },
    {
      // 购物车
      name:'shopcart',
      path: '/shopcart',
      component: ShopCart,
      meta: {
        isShow: true,
      }
    },
    {
      path: '/',
      redirect: '/home'
    },
  ]
})